package test.fork_join.compare.calculator;

import java.time.Duration;
import java.time.Instant;
import java.util.stream.LongStream;

public class ForLoopCalculator implements Calculator {

	@Override
    public long sumUp(long[] numbers) {
        long total = 0;
        for (long i : numbers) {
            total += i;
        }
        return total;
    }
	
	
	
	//写一个main方法进行测试：

    public static void main(String[] args) {
        long[] numbers = LongStream.rangeClosed(1, 100000000).toArray();

        Instant start = Instant.now();
        Calculator calculator = new ForLoopCalculator();
        long result = calculator.sumUp(numbers);
        Instant end = Instant.now();
        System.out.println("耗时：" + Duration.between(start, end).toMillis() + "ms");

        System.out.println("结果为：" + result); 
    }
/*输出：
耗时：10ms
结果为：50000005000000*/

	
	
}
